function Erev = findReversal(voltages, currents)

% Syntax:   Erev = findReversal(voltages, currents)
%
% Assumes that chord conductances are positive;
% i.e., that the I-V relationship increases monotonically
% from negative values towards reversal (Erev)

% GS 10/03


% find the first positive value in the currents vector;

% y = ax + b;

y1 = currents(min(find(currents>0)));
y0 = currents(min(find(currents>0))-1);

dy = y1 - y0;

x1 = voltages(min(find(currents>0)));
x0 = voltages(min(find(currents>0))-1);
dx = x1 - x0;

a = dy/dx;
b = currents(min(find(currents>0))) - a*voltages(min(find(currents>0)));

Erev = round(-b/a);